package com.winderinfo.yikaotianxia.ui.zixun;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.api.Api;
import com.winderinfo.yikaotianxia.core.base.BaseActivity;
import com.winderinfo.yikaotianxia.core.mvp.Contract;
import com.winderinfo.yikaotianxia.core.mvp.Presenter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InformationActivity extends BaseActivity implements Contract.View {

    @BindView(R.id.con_tab)
    TabLayout conTab;
    @BindView(R.id.con_viewpager)
    ViewPager conViewpager;
    private Presenter presenter;
    Map<String, Object> map = new HashMap<>();

    @Override
    protected int initLayoutId() {
        return R.layout.activity_consultation;
    }

    @Override
    protected void initView() {
        //实例P
        presenter = new Presenter(this);
    }

    @Override
    protected void initData() {
        //请求资讯分类
        presenter.onPostRequest(Api.ZIXUNFENLEI, null, InformationBean.class);
    }

    @Override
    public void onSuccess(Object data) {
        //资讯分类数据
        if (data instanceof InformationBean) {
            List<InformationBean.RowsBean> rows = ((InformationBean) data).getRows();
            //设置适配器
            InformationPagerAdapter informationPagerAdapter = new InformationPagerAdapter(getSupportFragmentManager(), rows);
            conViewpager.setAdapter(informationPagerAdapter);
            conTab.setupWithViewPager(conViewpager);
        }

    }

    @Override
    public void onFailure(Object error) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onUntying();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.con_banck)
    public void onViewClicked() {
        finish();
    }
}
